package org.flatshare.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.flatshare.entity.Invoice;
import org.flatshare.entity.User;

@Stateless
public class InvoiceDao implements InvoiceDaoRemote{

		@PersistenceContext(unitName = "flat-core")
		EntityManager em;
		
		public InvoiceDao(){
			
		}
		
		public List<Invoice> findAllInvoices(){
			TypedQuery<Invoice> invoices = em.createNamedQuery("findAllInvoices", Invoice.class);
			return invoices.getResultList();
			}
		
		public List<Invoice> findByTypeInvoices(){
			TypedQuery<Invoice> invoices = em.createNamedQuery("findByTypeInvoices", Invoice.class);
			return invoices.getResultList();
			}
		
		public Invoice findByIdInvoices(){
			TypedQuery<Invoice> invoices = em.createNamedQuery("findByIdInvoices", Invoice.class);
			return invoices.getSingleResult();
			}
		
		
		public void createInvoice(Invoice inv){			
			 em.persist(inv);
		}
				
		
		public User findUser(Integer id){
			
			return em.find(User.class, id);
		}
		
		public void removeUser(User usr){
			em.remove(usr);
		}
		
	}

